package models

import (
	"github.com/beego/beego/v2/client/orm"
	"ltbz/cultural_tourism_api/utils"
	"time"
)

type ReserveManage struct {
	ReserveManageId int       `orm:"column(reserve_manage_id);pk"`
	Mobile          string    `description:"手机号"`
	ReserveNum      string    `description:"预约码"`
	CreateTime      time.Time `description:"创建时间"`
	ModifyTime      time.Time `description:"修改时间"`
}

type ReserveManageView struct {
	ReserveManageId int       `description:"预约管理id"`
	Mobile          string    `description:"手机号"`
	ReserveNum      string    `description:"预约码"`
	CreateTime      time.Time `description:"创建时间"`
	ModifyTime      time.Time `description:"修改时间"`
}

func (obj *ReserveManage) AddReserveManage() (err error) {
	o := orm.NewOrm()
	_, err = o.Insert(obj)
	return
}

type ReserveManageAddReq struct {
	Mobile string `description:"手机号"`
}

type ReserveManageListReq struct {
	Mobile string `description:"手机号"`
	utils.PagingReq
}

func (r *ReserveManage) GetReserveManageCount(condition string, pars []interface{}) (count int, err error) {
	o := orm.NewOrm()
	sql := `SELECT COUNT(1) AS count FROM reserve_manage WHERE 1=1 `
	if condition != "" {
		sql += condition
	}
	err = o.Raw(sql, pars).QueryRow(&count)
	return
}

func (r *ReserveManage) GetReserveManagePage(condition string, pars []interface{}, startSize, pageSize int) (items []*ReserveManageView, err error) {
	o := orm.NewOrm()
	sql := `SELECT * FROM reserve_manage WHERE 1=1 `
	if condition != "" {
		sql += condition
	}
	sql += ` ORDER BY create_time DESC LIMIT ?,? `
	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
	return
}

type ReserveManagePageResp struct {
	List   []*ReserveManageView
	Paging *utils.PagingResp
}

type ReserveManageDelReq struct {
	ReserveManageId int `description:"预约管理id"`
}

func (r *ReserveManage) DeleteReserveManage(reserveManageId int) (err error) {
	o := orm.NewOrm()
	sql := `SELECT COUNT(1) AS count FROM reserve_manage WHERE reserve_manage_id = ? `
	_, err = o.Raw(sql, reserveManageId).Exec()
	return
}
